package com.langxin.site.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.langxin.site.biz.ReactionBiz;
import com.langxin.site.model.PageInfo;
import com.langxin.site.model.ReactionInfo;
import com.langxin.site.model.vo.QueryVo;

/**
 * 高原反应
 * @author guqj
 *
 */
@Controller
@RequestMapping("/fany")
public class ReactAction {

	@Autowired
	private ReactionBiz  reactionBiz;
	
	/**
	 * 列表
	 * @param model
	 * @param queryVo
	 * @param pageInfo
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String tour(Model model, QueryVo queryVo, PageInfo<ReactionInfo> pageInfo){
		reactionBiz.queryPage(queryVo, pageInfo);
		if(pageInfo.getRecords() == null || pageInfo.getRecords().size() == 0){
			return "redirect:/fany";
		}
		model.addAttribute("pageInfo", pageInfo);
		model.addAttribute("hots", reactionBiz.hot(4));
		return "react/react_list.jsp";
	}
	
	/**
	 * 详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String reactDetail(Model model, @PathVariable Integer id){
		ReactionInfo reactionInfo = reactionBiz.queryById(id);
		if(reactionInfo == null){
			return "error/404.jsp";
		}
		model.addAttribute("reactionInfo", reactionInfo);
		model.addAttribute("hots", reactionBiz.hot(4));
		return "react/react_detail.jsp";
	}
}
